// ----------------------------------------------------------------------------
// Copyright 2006, Martin D. Flynn
// All rights reserved
// ----------------------------------------------------------------------------
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Description:
//  OpenDMTP protocol server error constants.
// ----------------------------------------------------------------------------
// Change History:
//  2006/03/26  Martin D. Flynn
//      Initial release
//  2006/04/09  Martin D. Flynn
//      Added 'NAK_ACCOUNT_ERROR' and 'NAK_DEVICE_ERROR'
// ----------------------------------------------------------------------------
package org.opendmtp.j2me.codes;

/**
 * Contains OpenDMTP protocol server error constants.
 * 
 * @author Martin D. Flynn
 * @author Robert Puckett
 * 
 */
public interface ServerErrors {

  // ----------------------------------------------------------------------------
  // No error:

  /**
   * Contains a constant signifying no error.
   */
  public static final int NAK_OK = 0x0000;

  // ----------------------------------------------------------------------------
  // Account/Device errors:

  /**
   * Contains a constant signifying an account/device error for an invalid unique id. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when an invalid/unrecognized unique id was specified
   */
  public static final int NAK_ID_INVALID = 0xF011;

  /**
   * Contains a constant signifying an account/device error for an invalid/missing account id. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when account id is not recognized
   */
  public static final int NAK_ACCOUNT_INVALID = 0xF021;

  /**
   * Contains a constant signifying an account/device error for when an account has expired, or has
   * become inactive. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when account id is no longer active
   */
  public static final int NAK_ACCOUNT_INACTIVE = 0xF022;

  /**
   * Contains a constant signifying an account/device error for a server error that occured while
   * loading Account. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when server encountered an error on the Account
   */
  public static final int NAK_ACCOUNT_ERROR = 0xF023;

  /**
   * Contains a constant signifying an account/device error for an invalid/missing device id. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when device id is not recognized
   */
  public static final int NAK_DEVICE_INVALID = 0xF031;

  /**
   * Contains a constant signifying an account/device error for when a device has expired, or has
   * become inactive. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when this device id is no longer active
   */
  public static final int NAK_DEVICE_INACTIVE = 0xF032;

  /**
   * Contains a constant signifying an account/device error for when a server error occured while
   * loading Device. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when server encountered an error on the Device
   */
  public static final int NAK_DEVICE_ERROR = 0xF033;

  /**
   * Contains a constant signifying an account/device error for excessive connections. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when too many connections have been made in the alotted time.
   */
  public static final int NAK_EXCESSIVE_CONNECTIONS = 0xF041;

  // ----------------------------------------------------------------------------
  // Packet errors:

  /**
   * Contains a constant signifying a packet error for an invalid/Unsupported packet header. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the packet header is not recognized.
   */
  public static final int NAK_PACKET_HEADER = 0xF111;

  /**
   * Contains a constant signifying a packet error for an invalid/Unsupported packet type. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the packet type is not recognized.
   */
  public static final int NAK_PACKET_TYPE = 0xF112;

  /**
   * Contains a constant signifying a packet error for an invalid packet length. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the packet length is invalid.
   */
  public static final int NAK_PACKET_LENGTH = 0xF113;

  /**
   * Contains a constant signifying a packet error for an invalid packet payload. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the packet payload is invalid (in the case where the <br>
   * server is able to perform such validation).
   */
  public static final int NAK_PACKET_PAYLOAD = 0xF114;

  /**
   * Contains a constant signifying a packet error for when the encoding is not supported. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to the client when packet has been received using an encoding <br>
   * that is not supported by the server.
   */
  public static final int NAK_PACKET_ENCODING = 0xF115;

  /**
   * Contains a constant signifying a packet error for an invalid packet checksum (ASCII encoding
   * only). <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br> - Sent to client when the packet checksum appears to be invalid. <br>
   * This can only occur for ASCII encoded packets. <br> - This likely indicates a transmission
   * error. If this is the case <br>
   * then the server is unable to trust any information contained in the <br>
   * packet.
   */
  public static final int NAK_PACKET_CHECKSUM = 0xF116;

  // ----------------------------------------------------------------------------
  // Protocol errors:

  /**
   * Contains a constant signifying a protocol error for an invalid block checksum. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the block checksum appears to be invalid.
   */
  public static final int NAK_BLOCK_CHECKSUM = 0xF311;

  /**
   * Contains a constant signifying a protocol error for a general protocol error. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the server does not receive an expected <br>
   * response from the client.
   */
  public static final int NAK_PROTOCOL_ERROR = 0xF312;

  // ----------------------------------------------------------------------------
  // Event packet errors:

  /**
   * Contains a constant signifying an event packet error for when a custom format definition is
   * invalid. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * 4:1 - Custom format packet type <br>
   * Notes: <br> - Sent to client when the server has determined that the specified custom <br>
   * format definition is invalid. One of the following errors were found: <br> - The custom format
   * packet is invalid (ie. not within the proper range) <br> - The specified number of fields was
   * invalid. <br> - The combined field length is greater than the maximum payload length. <br> - A
   * specified field type was not recognized.
   */
  public static final int NAK_FORMAT_DEFINITION_INVALID = 0xF411;

  /**
   * Contains a constant signifying an event packet error for when custom formats are not supported.
   * <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br>
   * Sent to client when the server does not support custom format types, <br>
   * or if the level of service provide by the DMT service provider does <br>
   * not allow them.
   */
  public static final int NAK_FORMAT_NOT_SUPPORTED = 0xF421;

  /**
   * Contains a constant signifying an event packet error for when a custom format is not
   * recognized. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * Notes: <br> - Sent to client when the server does not recognize a custom format type <br>
   * sent by the client.
   */
  public static final int NAK_FORMAT_NOT_RECOGNIZED = 0xF422;

  /**
   * Contains a constant signifying an event packet error for excessive events. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * 4:X - Event sequence number (if available) <br>
   * Notes: <br> - Sent to client when too many events have been sent in the alotted time <br>
   * based on the current level of service. <br> - The server should only send this error AFTER it
   * sends any applicable ACK. <br> - When receiving this error, the client should act on it
   * accordingly by <br>
   * removing the offending sent event (if present), and pulling back on the <br>
   * number of generated events.
   */
  public static final int NAK_EXCESSIVE_EVENTS = 0xF431;

  /**
   * Contains a constant signifying an event packet error for when a duplicate event is found. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * 4:X - Event sequence number (if available) <br>
   * Notes: <br> - Sent to client when the server has determined that a sent event <br>
   * already exists in the database. <br> - This error is typically ignored on the client side since
   * there is usually <br>
   * little that the client can do about it anyway. As such, the server may <br>
   * optionally choose not to return this error to the client, but instead <br>
   * quietly ignore the duplicate event packet.
   */
  public static final int NAK_DUPLICATE_EVENT = 0xF432;

  /**
   * Contains a constant signifying an event packet error for when a generic event error is
   * detected. <br>
   * Payload: <br>
   * 0:2 - This error code <br>
   * 2:1 - Packet header causing error <br>
   * 3:1 - Packet type causing error <br>
   * 4:X - Event sequence number (if available) <br>
   * Notes: <br> - Sent to client when the server has encountered an error that <br>
   * prevented this event from being inserted into the database. <br> - This error is typically
   * ignored on the client side since there is usually <br>
   * little that the client can do about it anyway. As such, the server may <br>
   * optionally choose not to return this error to the client.
   */
  public static final int NAK_EVENT_ERROR = 0xF441;

}
